/*
 * Copyright (C) 2009 Jiannan Lu
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.restsql.atom;

import java.io.Serializable;
import java.io.UnsupportedEncodingException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author L
 */
public class Link implements Serializable {

    private String _href;
    private String _hrefResolved;
    private String _rel = "alternate";
    private String _type;
    private String _hreflang;
    private String _title;
    private long   _length;

    /**
     * Default constructor. All properties are set to <b>null</b>.
     * <p>
     *
     */
    public Link(String rel,String type,String href) {
       _rel = rel==""?_rel:rel;
       _type = type;
       _href = href;
    }

    /**
     * Indicates whether some other object is "equal to" this one as defined by the Object equals() method.
     * <p>
     * @param other he reference object with which to compare.
     * @return <b>true</b> if 'this' object is equal to the 'other' object.
     *
     */
    public boolean equals(Object other) {
        return this.equals(other);
    }

    /**
     * Returns a hashcode value for the object.
     * <p>
     * It follows the contract defined by the Object hashCode() method.
     * <p>
     * @return the hashcode of the bean object.
     *
     */
    public int hashCode() {
        return this.hashCode();
    }

    /**
     * Returns the String representation for the object.
     * <p>
     * @return String representation for the object.
     * @throws UnsupportedEncodingException
     *
     */
    
    public String toString(){
        StringBuilder sbLink = new StringBuilder();
            
            sbLink.append("<link ");
            sbLink.append("rel='" + _rel + "' ");
            sbLink.append("type='" + _type + "' ");
            sbLink.append("href='" + _href + "' ");
            sbLink.append(" />");
       
        return sbLink.toString();
    }

    /**
     * Returns the link rel.
     * <p>
     * @return the link rel, <b>null</b> if none.
     *
     */
    public String getRel() {
        return _rel;
    }

    /**
     * Sets the link rel.
     * <p>
     * @param rel the link rel,, <b>null</b> if none.
     *
     */
    public void setRel(String rel) {
        //TODO add check, ask P@ about the check
        _rel = rel;
    }

    /**
     * Returns the link type.
     * <p>
     * @return the link type, <b>null</b> if none.
     *
     */
    public String getType() {
        return _type;
    }

    /**
     * Sets the link type.
     * <p>
     * @param type the link type, <b>null</b> if none.
     *
     */
    public void setType(String type) {
        _type = type;
    }

    /**
     * Returns the link href.
     * <p>
     * @return the link href, <b>null</b> if none.
     *
     */
    public String getHref() {
        return _href;
    }

    /**
     * Sets the link href.
     * <p>
     * @param href the link href, <b>null</b> if none.
     *
     */
    public void setHref(String href) {
        _href = href;
    }

    public void setHrefResolved(String hrefResolved) {
        _hrefResolved = hrefResolved;
    }

    public String getHrefResolved() {
        return _hrefResolved != null ? _hrefResolved : _href;
    }

    /**
     * Returns the link title.
     * <p>
     * @return the link title, <b>null</b> if none.
     *
     */
    public String getTitle() {
        return _title;
    }

    /**
     * Sets the link title.
     * <p>
     * @param title the link title, <b>null</b> if none.
     *
     */
    public void setTitle(String title) {
        _title = title;
    }

    /**
     * Returns the hreflang
     * <p>
     * @return Returns the hreflang.
     * @since Atom 1.0
     */
    public String getHreflang() {
        return _hreflang;
    }

    /**
     * Set the hreflang
     * <p>
     * @param hreflang The hreflang to set.
     * @since Atom 1.0
     */
    public void setHreflang(String hreflang) {
        _hreflang = hreflang;
    }

    /**
     * Returns the length
     * <p>
     * @return Returns the length.
     */
    public long getLength() {
        return _length;
    }

    /**
     * Set the length
     * <p>
     * @param length The length to set.
     */
    public void setLength(long length) {
        _length = length;
    }
}
